package sisicotren.model.simulator;

import sisicotren.model.simulator.ChannelState;
import sisicotren.model.simulator.Client;
import java.util.List;
import java.util.LinkedList;
import java.util.Observable;

public class Channel extends Observable {

	public Channel(Double attentionRate) {
		super();
		state = ChannelState.IDLE;
		attRate = attentionRate;
		servedClients = new LinkedList<Client>();
	}

	public ChannelState getCurrentState() {
		return state;
	}
	
	public void setCurrentState(ChannelState newState) {
		if(state != newState) {
			state = newState;
			setChanged();
			notifyObservers();
		}
	}
	
	public void inject(Client aClient) {
		//if(state != ChannelState.IDLE)
		//	return;
		setCurrentState(ChannelState.BUSY);
		servedClients.add(aClient);
	}
	
	public Double getAttentionRate() {
		return attRate;
	}
	
	public void on() {
		state = ChannelState.IDLE;
	}
	
	public void off() {
		state = ChannelState.OFF;
	}
	
	public List<Client> getServedClients() {
		return servedClients;
	}
	
	private ChannelState state;
	private Double attRate;
	private List<Client> servedClients;
}
